//
//  SISSPassengerResourceDetailVC.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/20.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerResourceDetailVC.h"
#import "SISSMorePopupView.h"
#import "SISSRecommendHouseViewController.h"


@interface SISSPassengerResourceDetailVC ()<SISSMorePopupViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *nameAndPurposeLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAndCommunityLabel;
@property (weak, nonatomic) IBOutlet UILabel *budgetLabel;
@property (weak, nonatomic) IBOutlet UILabel *houseTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *areaLabel;
@property (weak, nonatomic) IBOutlet UILabel *intentionFloorLabel;
@property (weak, nonatomic) IBOutlet UILabel *decorationLabel;
@property (weak, nonatomic) IBOutlet UILabel *directionLabel;
@property (weak, nonatomic) IBOutlet UILabel *purchasePurposeLabel;
@property (weak, nonatomic) IBOutlet UILabel *otherDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *insertTimeLabel;

@property (weak, nonatomic) IBOutlet UIButton *recommendButton;
@end

@implementation SISSPassengerResourceDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加右侧分享投诉按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"more..."] style:UIBarButtonItemStylePlain target:self action:@selector(shareAndComplainClick)];
    
    self.recommendButton.hidden = self.isHideBottomButton;
    
}

- (void)setPassengerModel:(SISSPassengerResourceModel *)passengerModel {
    [self.view layoutIfNeeded];
    _passengerModel = passengerModel;
    
    if (passengerModel.demandType != 2 && passengerModel.idNumber.length > 0) {
        
        // 根据身份证判断显示 先生、女士
        NSString *fisrtName = [passengerModel.name substringToIndex:1];
        NSInteger idNum = [[passengerModel.idNumber substringWithRange:NSMakeRange(passengerModel.idNumber.length - 2, 1)] integerValue];
        
        NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
        self.nameAndPurposeLabel.text = [NSString stringWithFormat:@"%@%@  %@",fisrtName,genderStr,@"求购"];
    } else {
        self.nameAndPurposeLabel.text = [NSString stringWithFormat:@"%@  %@",passengerModel.name,@"求购"];
    }

    self.regionAndCommunityLabel.text = [NSString stringWithFormat:@"%@-%@ %@",passengerModel.region,passengerModel.regionDetail,passengerModel.neighbourhood.length > 0 ? passengerModel.neighbourhood : @""];
    self.budgetLabel.text = [NSString stringWithFormat:@"%.0f-%.0f万",passengerModel.minPrice,passengerModel.maxPrice];
    self.houseTypeLabel.text = passengerModel.houseType;
    self.areaLabel.text = [NSString stringWithFormat:@"%.0f-%.0f㎡",passengerModel.minArea,passengerModel.maxArea];
    self.intentionFloorLabel.text = (passengerModel.minFloor != 0 && passengerModel.maxFloor != 0) ? [NSString stringWithFormat:@"%zd-%zd层",passengerModel.minFloor,passengerModel.maxFloor]: @"暂无数据";
    self.decorationLabel.text = passengerModel.decoration.length ? passengerModel.decoration : @"暂无数据";
    self.directionLabel.text = passengerModel.direction.length ? passengerModel.direction : @"暂无数据";
    self.purchasePurposeLabel.text = passengerModel.purpose.length ? passengerModel.purpose : @"暂无数据";
    self.otherDescriptionLabel.text = passengerModel.otherdesc.length ? passengerModel.otherdesc : @"暂无数据";
    self.insertTimeLabel.text = [NSDate yyr_stringToString:passengerModel.insertTime];
}


/**
 推荐房源按钮点击事件
 */
- (IBAction)recommendButtonClickAction:(UIButton *)sender {
    
    SISSRecommendHouseViewController *vc = [[SISSRecommendHouseViewController alloc] init];
    vc.title = @"房源列表";
    vc.isFind = self.isFind;
    vc.isDetailIn = YES;
    vc.abdId = self.passengerModel.ID;
    [self.navigationController pushViewController:vc animated:YES];
}

/**
 分享投诉按钮事件
 */
- (void)shareAndComplainClick {
    
    SISSMorePopupView *moreView = [[SISSMorePopupView alloc] initWithTitles:@[@"分享", @"举报"]];
    moreView.delegate = self;
    [moreView show];
}

#pragma mark - SISSMorePopupViewDelegate
- (void)morePopupViewSelectedWithIndex:(NSInteger)index {
    
    if (index == 0) {
        // 根据身份证判断显示 先生、女士
        NSString *fisrtName = [self.passengerModel.name substringToIndex:1];
        NSInteger idNum = [[self.passengerModel.idNumber substringWithRange:NSMakeRange(self.passengerModel.idNumber.length - 2, 1)] integerValue];
        
        NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
        NSString *title = [NSString stringWithFormat:@"%@%@ 求购",fisrtName,genderStr];
        NSString *descr = [NSString stringWithFormat:@"%@-%@ | %@-%@ | %@",@(self.passengerModel.minPrice),@(self.passengerModel.maxPrice),self.passengerModel.region,self.passengerModel.regionDetail,self.passengerModel.houseType];
        NSString *webpageUrl = @"";
        if (self.passengerModel.demandType == 1) { // 线上
            webpageUrl = [NSString stringWithFormat:@"%@/?#!/buyerDetail/%@/",WEB_BASE_URL,self.passengerModel.ID];
        } else { // 线下
            webpageUrl = [NSString stringWithFormat:@"%@/?#!/offlineDemandDetail/%@",WEB_BASE_URL,self.passengerModel.ID];
        }
        
        [[SISSPublicSingleton shared] shareWithTitle:title descr:descr webpageUrl:webpageUrl currentViewController:self thumImage:nil];
    } else {
        
        SISSReportViewController *vc = [[SISSReportViewController alloc] init];
        vc.isReportPassenger = YES;
        vc.passengerModel = self.passengerModel;
        
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}



@end
